package com.example.task1.ui.AllService.movies;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.MoniesFilmBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class MoviesFilmPreviewAdapter extends BaseAdapter<MoniesFilmBean.RowsDTO> {

    private Context context;
    private List<MoniesFilmBean.RowsDTO> data = new ArrayList<>();
    private ImageView image;
    private TextView tvTitle;
    private TextView tvPlayDate;
    private TextView tvIntroduction;

    public MoviesFilmPreviewAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<MoniesFilmBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.moviesfilmprevivewlist;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<MoniesFilmBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, MoniesFilmBean.RowsDTO date) {
        MyApplication.glide(image, date.getCover());
        tvTitle.setText(date.getName());
        tvPlayDate.setText("上映时间：" + date.getPlayDate());
        tvIntroduction.setText("简介：" + Html.fromHtml(date.getIntroduction()));
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        image = (ImageView) itemView.findViewById(R.id.image);
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvPlayDate = (TextView) itemView.findViewById(R.id.tv_playDate);
        tvIntroduction = (TextView) itemView.findViewById(R.id.tv_introduction);
    }
}
